﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCAutocomplete.ascx.cs" Inherits="WebUI.UserControls.UCAutocomplete" %>

    <div class="div_border_textbox" style="width:310px; float:left; margin-bottom:15px;">
        <asp:TextBox ID="txtSearch" runat="server" MaxLength="200" Font-Size="12px" placeholder="enter your key word" CssClass="csstextbox" Width="306px"></asp:TextBox>
    </div>
    <div class="findresultbutton"><%=GetText("AdlerMaster.btnSearch")%></div>
    <div class="text menutext"><%=GetText("AdlerMaster.Tips")%></div>
    <script type="text/javascript">
        $(document).ready(function () {
            SearchText();
        });
        function SearchText() {
            $("#<%=txtSearch.ClientID %>").autocomplete({
                minLength: 2,
                delay: 500,
                autoFocus: true,
                source: function (request, response) {
                    $.ajax({
                        type: "GET",
                        contentType: "application/json; charset=utf-8",
                        url: "JSonHandler.ashx",
                        data: { keyWord: $("#<%=txtSearch.ClientID %>").val() },
                        dataType: "json",
                        success: function (data) {
                            var returnData = data;
                            response(returnData);

                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                },
                select: function (event, ui) {
                    event.preventDefault();
                    if (ui.item.value != "null") {
                        var link = ui.item.label;
                        $("#<%=txtSearch.ClientID %>").val(link);
                        window.open(ui.item.value, "_self");
                    }
                },
                focus: function (event, ui) {
                    event.preventDefault();
                    if (ui.item.value != "null")
                        $("#<%=txtSearch.ClientID %>").val(ui.item.label);
                    else {

                        $(this).val = "";

                    }
                }
            });
        }
    </script>